import json
from flask import Flask, jsonify, request
from config.path_manage import  get_mock_data_path


# 实例化一个flask应用
app = Flask(__name__)
MOCK_DATA_FILE = get_mock_data_path()

# 读取mock的路径
with open(MOCK_DATA_FILE, "r") as file:
    mock_data = json.load(file)



# @app.route("/api/basedata/storecenter/query", methods=["GET"])
# def basedata_storecenter_query():
#     return jsonify({"code":200, "id":"222"})


@app.route('/<path:path>', methods=["GET", "POST", "PUT","DELETE"])
def basedata_storecenter_query(path):

    method = request.method

    key = method.upper() + f" /{path}"

    for k, value in mock_data.items():
        if key == k:
            status_code = value.get("status_code", 200)
            response = value.get("response", {})
            return jsonify(response), status_code
    return jsonify({"code": 404, "msg": f"No mock data found for {key}"}), 404


if __name__ == '__main__':
    app.run(debug=True)



